package com.letfox.ad.controller.statis;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.letfox.ad.controller.BaseController;
import com.letfox.ad.service.UDMStatisticService;
import com.letfox.common.enums.ResponseEnum;
import com.letfox.common.model.ResultResponse;
import com.letfox.statistical.model.UDMDeviceStatistic;
import com.letfox.statistical.model.UDMGeoStatistic;
import com.letfox.statistical.model.UDMMediaStatistic;

@Controller
@RequestMapping(value = "/statistic")
public class DataStatisControlle extends BaseController{
	
	private Logger logger = LoggerFactory.getLogger(getClass());
	
	@Autowired
	private UDMStatisticService udmStaticService;
	
	/**
	 * 时间范围（日期）+设备+广告ID
	 * @param adPutintoId
	 * @param device
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	@RequestMapping(value = "/getDavice",method=RequestMethod.POST)
	@ResponseBody
	public ResultResponse getDdviceStatisic(@RequestParam String adPutintoId,@RequestParam String device
			,@RequestParam String startTime,@RequestParam String endTime){
		List<UDMDeviceStatistic> getDeviceList=null;
		try {
			getDeviceList=udmStaticService.getDeviceList(adPutintoId, device, startTime, endTime);
			resultResponse.setData(getDeviceList);
			resultResponse.setStatusCode(ResponseEnum.R200.getCode());
			resultResponse.setStatusMessage(ResponseEnum.R200.getMessage());
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			resultResponse.setStatusCode(ResponseEnum.R500.getCode());
			resultResponse.setStatusMessage(ResponseEnum.R500.getMessage());
		}
		return resultResponse;
	}
	
	/**
	 * c.时间范围（日期）+媒体+广告ID
	 * @param adPutintoId
	 * @param media
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	@RequestMapping(value = "/getMedia",method=RequestMethod.POST)
	@ResponseBody
	public ResultResponse getMediaStatisic(@RequestParam String adPutintoId,@RequestParam String media
			,@RequestParam String startTime,@RequestParam String endTime){
		List<UDMMediaStatistic> getMediaList=null;
		try {
			getMediaList=udmStaticService.getMediaList(adPutintoId, media, startTime, endTime);
			resultResponse.setData(getMediaList);
			resultResponse.setStatusCode(ResponseEnum.R200.getCode());
			resultResponse.setStatusMessage(ResponseEnum.R200.getMessage());
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			resultResponse.setStatusCode(ResponseEnum.R500.getCode());
			resultResponse.setStatusMessage(ResponseEnum.R500.getMessage());
		}
		return resultResponse;
	}
	
	/**
	 * 时间范围（日期）+区域+广告ID
	 * @param adPutintoId
	 * @param geo
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	@RequestMapping(value = "/getGeo",method=RequestMethod.POST)
	@ResponseBody
	public ResultResponse getGeoStatisic(@RequestParam String adPutintoId,@RequestParam String geo
			,@RequestParam String startTime,@RequestParam String endTime){
		List<UDMGeoStatistic> getGeoList=null;
		try {
			getGeoList=udmStaticService.getGeoList(adPutintoId, geo, startTime, endTime);
			resultResponse.setData(getGeoList);
			resultResponse.setStatusCode(ResponseEnum.R200.getCode());
			resultResponse.setStatusMessage(ResponseEnum.R200.getMessage());
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			resultResponse.setStatusCode(ResponseEnum.R500.getCode());
			resultResponse.setStatusMessage(ResponseEnum.R500.getMessage());
		}
		return resultResponse;
	}

}
